import {
    Refresh
} from "@/api/modules/user"
import {
    setAccessToken
} from "@/utils/auth"
import router from "@/router"
// 刷新AccessToken的函数
export function refreshAccessToken() {
    return new Promise((resolve, reject) => {
        try {
            console.log("isrefresh")
            Refresh().then(success => {
                console.log('refresh', success);
                if (success.status == 200) {
                    console.log("access", success.data.AccessToken)
                    setAccessToken(success.data.AccessToken); // 设置新的AccessToken到请求头
                    resolve(true) // 刷新AccessToken成功
                } else {
                    resolve(false)
                }
            }).catch(error => {
                if (error.response && error.response.status == 401) {
                    router.push("/login")
                } else {
                    console.log(error)
                    reject("error")
                }

            }); // 假设Refresh函数用于刷新AccessToken
        } catch (error) {
            console.log('refresh error:', error);
            reject("error")
        }
    })

}